package il.technion.ewolf.kbr.openkad.msg;

import il.technion.ewolf.kbr.Key;
import il.technion.ewolf.kbr.Node;

import com.google.inject.Inject;
import com.google.inject.name.Named;

/**
 * A findValue request as defined in the kademlia protocol
 * 
 * @author Ligal ligal2@gmail.com
 * @author Hen senderhen@gmail.com
 */
public class FindValueRequest extends KadRequest {

	private static final long serialVersionUID = -7084922793331210968L;
	private Key key;
	private boolean replicationFlag = false;
	
	@Inject
	FindValueRequest(
			@Named("openkad.rnd.id") long id,
			@Named("openkad.local.node") Node src) {
		super(id, src);
	}

	/** 
	 * @return the key we are searching
	 */
	public Key getKey() {
		return key;
	}
	
	/***
	 * Sets the key that is searched
	 * @param key 
	 * @return the message
	 */
	public FindValueRequest setKey(Key key) {
		this.key = key;
		return this;
	}

	/** 
	 * @return whether the request is part of replication process
	 */
	public boolean getFlag() {
		return replicationFlag;
	}
	
	/***
	 * Sets the flag that indicates if the request is part of replication process
	 * @param flag
	 * @return the message
	 */
	public FindValueRequest setFlag(boolean flag) {
		this.replicationFlag = flag;
		return this;
	}
	
	@Override
	public FindValueResponse generateResponse(@Named("openkad.local.node") Node localNode) {
		return new FindValueResponse(getId(), localNode);
	}

}
